#include "StdAfx.h"
#include "DPlayer.h"
#include "../Engine/DAnimation.h"
#include "../Game/DGame.h"
#include "../Engine/DInput.h"
#include "Weapons/DWeapon.h"

DPlayer::DPlayer(boost::shared_ptr<DGame> game)
: DIActor(game)
{
    
}

DPlayer::~DPlayer(void)
{
}

std::map<std::string, std::string> DPlayer::animationList() const
{
	std::map<std::string, std::string> animList;
	animList["Flying"] = "Player/Flying";
	return animList;
}

void DPlayer::update(float dt)
{
    boost::shared_ptr<DInput> input = m_game.lock()->input();

    float mx = input->mousePosX();
	float my = input->mousePosY();

    float w = (float)currentAnimation()->width();
    float h = (float)currentAnimation()->height();

    setPos(vec2(mx - w/2, my - h/2));

    vec2 bulletOffset(82, 47);
    vec2 bulletPos = pos() + bulletOffset;
    if(input->mouseButtonDown(DMOUSE_BUTTON_LEFT))
    {
        m_weapon->fire(m_game.lock(), bulletPos, vec2(1.0f, 0.0f), dt);
    }

	m_currentAnim.lock()->update(dt);
}

void DPlayer::initWeapons()
{
    m_weapon.reset(new Weapons::DWeapon(shared_from_this()));
    m_weapon->setType(Weapons::DWeapon::eFirebolt);
}